//提供暴露接口
// import request from "@/utils/request.ts";
//管理学生相关的接口

import type { getClassGroupsResponse, getStudentGroupScoreResponse, getGroupListrDatePrams, studentGetGroupResponse, getGroupsMemberDatePrams, StudentUploadDto, studentLogin, loginResponseDate, studentRegister, registerResponse, studentForgetPassword, studentGetIndividualProResponse, studentUpdate, getStudentGroupResponse, CreateGroupParams, pushNoticeParams, uploadUrlParams, applyEnterGroupsParams, applyEnterResponse } from "./type";
import request from "@/utils/request";
enum API {
    LOGIN_URL = "/student/login",
    REGISTER_URL = "/student/register",
    FORGET_URL = "/student/forget-password",
    GETINDIVIDUALPRO_URL = "/student/get-individual-pro",
    UPDATE_URL = "/student/update",
    UPLOAD_URL = "/student/upload",
    UPLOAD_GROUP_URL = "/group/upload",
    GET_GROUP_LIST_URL = "/student/group-info/page",
    DELETE_GROUP_URL = "/student/delete-group",
    CREATE_GROUP_URL = "/student/create-group",
    CREATE_PRO_URL = "/student/create-pro",
    STUDENT_ENTER_NEXT_URL = "/student/enter-next",
    GET_GROUP_URL = "/group/get-group-info",
    GET_GROUP_SCORE_LIST_URL = "student/get-groupScore/page",
    PUSH_NOTICE_URL = "/student/push-notice",
    GROUP_ENTER_NEXT_URL = "/group/enter-next",
    UPLOAD_GITEE_URL = "group/add-gitee-url",
    GET_CLASS_GROUPS_URL = "/class/get-groups",
    APPLY_ENTER_GROUP_URL = "/student/enter-group",
    ALLOW_ENTER_GROUP_URL = "/student/allow",
    REJECT_ENTER_GROUP_URL = "/student/reject",
    STUDENT_GO_BACK_URL = "/student/go-back",
    GROUP_GO_BACK_URL = "/group/go-back"
}

//暴露请求函数
//登录接口的方法
export const reqStudentLogin = (data: studentLogin) => request.post<studentLogin, loginResponseDate>(API.LOGIN_URL, data);

//注册接口的方法
export const reqStudentRegister = (data: studentRegister) => request.post<studentRegister, registerResponse>(API.REGISTER_URL, data);


//忘记密码接口的方法
export const reqStudentForgetPassword = (data: studentForgetPassword) => request.post<studentForgetPassword, registerResponse>(API.FORGET_URL, data);

//获取个人信息接口的方法
export const reqStudentGetIndividualPro = (data: number) =>
    request.get<number, studentGetIndividualProResponse>(
        API.GETINDIVIDUALPRO_URL,
        { params: { studentId: data } } // 将 studentId 作为查询参数传递
    );

// 更新接口的方法
export const reqStudentUpdateInfo = (data: studentUpdate) =>
    request.post<studentUpdate, registerResponse>(API.UPDATE_URL, data);

//学生文件上传接口的方法
export const reqUploadFile = (data: StudentUploadDto): Promise<loginResponseDate> => {
    const formData = new FormData();
    formData.append('file', data.file);
    formData.append('studentId', data.studentId.toString()); // 添加 studentId
    return request.post(API.UPLOAD_URL, formData, {
        headers: {
            'Content-Type': 'multipart/form-data',
        },
    });
};

//允许学生进入小组的接口
export const reqAllowEnterGroup = (studentId: number) => {
    return request.put<number, loginResponseDate>(`${API.ALLOW_ENTER_GROUP_URL}`, {}, { params: { studentId } });
};
//拒绝学生进入小组的接口
export const reqRejectEnterGroup = (studentId: number) => {
    return request.put<number, loginResponseDate>(`${API.REJECT_ENTER_GROUP_URL}`, {}, { params: { studentId } });
};

//小组文件上传接口的方法
export const reqUploadGroupFile = (data: StudentUploadDto): Promise<loginResponseDate> => {
    const formData = new FormData();
    formData.append('file', data.file);
    formData.append('studentId', data.studentId.toString()); // 添加 studentId
    return request.post(API.UPLOAD_GROUP_URL, formData, {
        headers: {
            'Content-Type': 'multipart/form-data',
        },
    });
};

//获取自己小组成员信息的接口
export const reqGetGroupList = (params: getGroupsMemberDatePrams) => {
    return request.get<getGroupsMemberDatePrams, getStudentGroupResponse>(API.GET_GROUP_LIST_URL, { params });
};

//删除小组的接口
export const reqDisbanGroup = (studentId: string) => {
    return request.delete<string, loginResponseDate>(API.DELETE_GROUP_URL, { params: { studentId } });
};
//创建小组的接口
export const reqCreateGroup = (data: CreateGroupParams) => {
    return request.post<CreateGroupParams, loginResponseDate>(API.CREATE_GROUP_URL, data);
};

//创建项目的接口
export const reqCreatePro = (data: CreateGroupParams) => {
    return request.post<CreateGroupParams, loginResponseDate>(API.CREATE_PRO_URL, data);
};

//学生进入下一阶段
export const reqStudentEnterNext = (studentId: string) => {
    return request.put<string, loginResponseDate>(`${API.STUDENT_ENTER_NEXT_URL}`, {}, { params: { studentId } });
};

//学生回到上一阶段
export const reqStudentGoback = (studentId: string) => {
    return request.put<string, loginResponseDate>(`${API.STUDENT_GO_BACK_URL}`, {}, { params: { studentId } });
};

//获取小组项目信息的接口
export const reqStudentGetGroup = (studentId: string) => {
    return request.get<string, studentGetGroupResponse>(API.GET_GROUP_URL, { params: { studentId } });
}

//获取自己小组成员成绩信息的接口
export const reqGetGroupScoreList = (params: getGroupListrDatePrams) => {
    return request.get<getGroupListrDatePrams, getStudentGroupScoreResponse>(API.GET_GROUP_SCORE_LIST_URL, { params });
};

//获取自己小组成员成绩信息的接口
export const reqPushNotice = (data: pushNoticeParams) => {
    return request.post<pushNoticeParams, loginResponseDate>(API.PUSH_NOTICE_URL, data);
};

//小组进入下一阶段
export const reqGroupEnterNext = (studentId: string) => {
    return request.put<string, loginResponseDate>(`${API.GROUP_ENTER_NEXT_URL}`, {}, { params: { studentId } });
};

//小组回到上一阶段
export const reqGroupGoBack = (studentId: string) => {
    return request.put<string, loginResponseDate>(`${API.GROUP_GO_BACK_URL}`, {}, { params: { studentId } });
};
//上传Url信息的接口
export const reqUploadUrl = (data: uploadUrlParams) => {
    return request.post<uploadUrlParams, loginResponseDate>(API.UPLOAD_GITEE_URL, data);
};

//获取班级已经存在的小组信息的接口
export const reqGetClassGroup = (classId: string) => {
    return request.get<string, getClassGroupsResponse>(API.GET_CLASS_GROUPS_URL, { params: { classId } });
}

//申请加入小组的接口
export const reqApplyEnterGroup = (data: applyEnterGroupsParams) => {
    return request.post<applyEnterGroupsParams, applyEnterResponse>(API.APPLY_ENTER_GROUP_URL, data);
}